<template>
  <Layout>
    <div ref="mainContainer" class="main-container" v-loading="isLoading">
      <BlogDetail :blog="data" v-if="data"></BlogDetail>
      <BlogComment v-if="!isLoading"></BlogComment>
    </div>
    <template v-slot:right>
      <div class="right-container" v-loading="isLoading">
        <BlogToc :toc="data.toc" v-if="data"></BlogToc>
      </div>
    </template>
  </Layout>
</template>

<script>
import fetchData from '@/mixins/fetchData';
import { getBlog } from '@/api/blog';
import Layout from "@/components/Layout"
import BlogDetail from './components/BlogDetail.vue';
import BlogToc from './components/BlogToc.vue';
import BlogComment from "./components/BlogComment";
import mainScroll from "@/mixins/mainScroll";
export default {
  components: {
    Layout,
    BlogDetail,
    BlogToc,
    BlogComment
  },
  mixins: [fetchData(null), mainScroll("mainContainer", "Detail")],
  methods: {
    async fetchData() {
      return await getBlog(this.$route.params.id)
    },
  },
  updated() {
    const hash = location.hash;
    location.hash = "";
    setTimeout(() => {
      location.hash = hash;
    }, 50);
  }
}
</script>

<style scoped lang="scss">
.main-container {
  overflow-y: scroll;
  height: 100%;
  box-sizing: border-box;
  padding: 20px;
  position: relative;
  width: 100%;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.right-container {
  width: 300px;
  height: 100%;
  overflow-y: scroll;
  box-sizing: border-box;
  position: relative;
  padding: 20px;
}
</style> 